from sqlalchemy import Table,MetaData

from common.database import dbconnect
from main import db
from module.users import Users

dbsession,metatdata,DBbase = dbconnect()

class Article(DBbase):
    __table__ =Table('article',MetaData(bind=db.engine),autoload=True)

    def find_all(self):
        result = dbsession.query(Article).all()
        return result

    def find_by_id(self,article_id):
        row = dbsession.query(Article).filter_by(article_id=article_id).first()
        return row


    def find_limit_with_users(self,start,count):
        result = dbsession.query(Article,Users).jion(Users,Users.user_id==Article.user_id).order_by(
            not Article.article_id.dsec()).limit(count).offset(start).all()
        return result